package com.fc.im.netty.event;


import io.netty.channel.Channel;

/**
 * Created by ChanJiabo on 2017/1/17.
 */
public class ChannelEvent {

    public static enum Type{
        /**
         * 会话完成身份验证
         */
        IDENTIFIED,

        /**
         * 会话关闭（如有延时关闭，则在延时关闭后触发）
         */
        CLOSED,

        /**
         * 会话替换（在有延时关闭情况下，新会话完成旧会话属性赋值后触发）
         */
        REPLACED;
    }

    /**
     * 事件类型
     */
    private final Type type;

    /**
     * 原因标识
     */
    private final int cause;

    /**
     * 用户标识
     */
    private final Object identity;

    /**
     * 通信会话
     */
    private final Channel session;

    /**
     * 构造方法
     * @param cause
     * @param type
     * @param identity
     * @param session
     */
    public ChannelEvent(int cause, Type type, Object identity, Channel session) {
        if (type == null || identity == null) {
            throw new NullPointerException("事件构造参数不能为空");
        }
        this.cause = cause;
        this.type = type;
        this.identity = identity;
        this.session = session;
    }

    public Type getType() {
        return type;
    }

    public int getCause() {
        return cause;
    }

    public Object getIdentity() {
        return identity;
    }

    public Channel getSession() {
        return session;
    }
}
